/*
 * Progetto, a new java application 
 *
 * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
 * indicated by the @author tags or express copyright attribution
 * statements applied by the authors.  All third-party contributions are
 * distributed under license by Red Hat Inc.
 *
 * This copyrighted material is made available to anyone wishing to use, modify,
 * copy, or redistribute it subject to the terms and conditions of the GNU
 * Lesser General Public License, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this distribution; if not, write to:
 * Free Software Foundation, Inc.
 * 51 Rattazzi Street, Fifth Floor
 * Pomezia, RM  00040  Italy
 */
package com.jfootball.service.impl;

import java.util.List;
import java.util.Locale;

import org.directwebremoting.annotations.RemoteProxy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jfootball.dao.PositionDao;
import com.jfootball.domain.Position;
import com.jfootball.service.PositionService;

/**
 * @author C_ICTDNS
 *
 */
@Transactional(readOnly = true)
@Service("positionService")
@RemoteProxy(name = "positionService")
public class PositionServiceImpl implements PositionService
{
	private PositionDao positionDAO;
	
	private MessageSource messageSource;
	
	@Autowired
	public PositionServiceImpl(PositionDao positionDAO) 
	{
		this.positionDAO = positionDAO;
	}	
	

	public void savePosition(Position obj)
	{
		positionDAO.saveOrUpdatePosition(obj);
	}
	
	public List<Position> getPositionsByRole(String codRuolo, String locale)
	{
		List<Position> positions = positionDAO.listPositions(codRuolo);
		
		for (Position position : positions)
		{
			position.setDescPosizione(messageSource.getMessage(position.getDescPosizione(), null, new Locale(locale)));
		}
		
		return positions;
	}
	

	public Position getPositionByID(Long positionId)
	{
		return positionDAO.getPositionByID(positionId);
	}
	

	public void deletePosition(Long positionId)
	{
		positionDAO.deletePosition(positionId);
	}

	
	@Autowired
	public void setMessageSource(MessageSource messageSource) {
		this.messageSource = messageSource;
	}

}
